package nix.generic;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

/**
 * 泛型集合
 * 
 * @author berry
 * 
 */
public class TestGenericList {

	public static void main(String[] args) {

		List<String> list = new ArrayList<String>();
		list.add("aa");
		list.add("bb");
		list.add("cc");

		for (int i = 0; i < list.size(); i++) {
			System.out.println(list.get(i));
		}
		System.out.println("---------------------");
		for (String str : list) {
			System.out.println(str);
		}
		System.out.println("---------------------");
		Iterator it = list.iterator();
		while (it.hasNext()) {
			String str = (String) it.next();
			System.out.println(str);
		}
		System.out.println("---------------------");

		Set<String> set = new HashSet<String>();
		set.add("aa");
		set.add("bb");
		set.add("cc");

		for (String str : set) {
			System.out.println(str);
		}
		System.out.println("---------------------");
		Iterator it2 = set.iterator();
		while (it2.hasNext()) {
			String str = (String) it2.next();
			System.out.println(str);
		}
		System.out.println("---------------------");

		Map<String, String> map = new HashMap<String, String>();
		map.put("123", "aa");
		map.put("456", "bb");
		map.put("789", "cc");

		Set<String> setKey = map.keySet();
		for (String key : setKey) {
			System.out.println(key + ": " + map.get(key));
		}
		System.out.println("---------------------");
		Set<Entry<String, String>> setEntry = map.entrySet();
		for (Entry<String, String> entry : setEntry) {
			System.out.println(entry.getKey() + ": " + entry.getValue());
		}
	}
}
